<? 
	include('base.php');
	User::protect();
	$section = 'band_news';
	include_class('band_members');
	include_class('band_news');
	$no = BandNews::get($_GET['id']);

	if (!db::isError($no)) {
		switch ($_GET['task']) {
			case 'update':
				$res = $no->update($_POST);
				if (!db::isError($res)) { 
					header('Location: band_news_edit.php?id=' . $_GET['id']);
				}
				break;
			case 'deactivate':
				$res = $no->deactivate();
				if (!db::isError($res)) { 
					header('Location: band_news_edit.php?id=' . $_GET['id']);
				}
				break;
			case 'activate':
				$res = $no->activate();
				if (!db::isError($res)) { 
					header('Location: band_news_edit.php?id=' . $_GET['id']);
				}
				break;
			case 'delete':
				$res = $no->remove();
				if (!db::isError($res)) { 
					header('Location: band_news.php');
				}
				break;
		}
	}
	if ($_GET['task'] == 'edit' || $_GET['task'] == 'update') { 
		$calendar = true;
		$editors = array('description', 'body');
	}
	$page_title = 'Edit Band News';
	include('layout/header.php');
?>

<div id="breadcrumb">
	<a href="index.php">Audition&nbsp;&#62;</a>&nbsp;<a href="band.php">Manage&nbsp;Band&nbsp;&#62;</a>&nbsp;<a href="band_news.php">Band News&nbsp;&#62;</a>&nbsp;News Entry
</div>

<?
if ($res) { // it's an error
	if (db::isError($res)) {
		$res->outputList();
	}
}	

if (!db::isError($no)) { ?>
	<? if (($_GET['task'] == 'edit' || $_GET['task'] == 'update') && $no->canEdit()) { 
	
		
		$title = ($_POST) ? $_POST['title'] : $no->getTitle();
		$user_id = ($_POST) ? $_POST['user_id'] : $no->getUserID();
		$date = ($_POST) ? $_POST['date'] : $no->getDate();
		$time = ($_POST) ? $_POST['time'] : $no->getTime();
		$description = ($_POST) ? $_POST['description'] : $no->getDescription();
		$body = ($_POST) ? $_POST['body'] : $no->getBody();
		?>		
		<h1>edit entry:</h1>
		<div class="inset">
		<form id="edit_entry" action="<?=$PHP_SELF?>?task=update&amp;id=<?=$_GET['id']?>" method="post">
		<table border="0" class="edit-form" cellspacing="0" cellpadding="0">
		<? if (!$no->isActive()) { ?>
		<tr>	
			<td>&nbsp;</td>
			<td colspan="3" class="fieldname">This entry is inactive.</td>
		</tr>
		<? } ?>
		<tr>
			<td colspan="3" valign="top">
			<strong>Headline</strong><br/>
			<input type="text" value="<?=$title?>" class="text" name="title">
			</td>
		</tr>
		<tr>
			<td width="33%"><strong>Poster</strong> (* - inactive)<br/>
			<? if (User::isAdmin()) { ?>
					<select name="user_id">
						<?
						$ul = new UserList();
						$uArray = $ul->getAdminUsers();
						foreach ($uArray as $uo) { ?>
							<option class="admin-user" value="<?=$uo->getID()?>"<? if ($user_id == $uo->getID()) { ?> SELECTED<? } ?>><?=$uo->getFirstName()?><? if (!$uo->isActive()) { ?> *<? } ?></option>
						<? }
						
						$bmlist = new BandMemberList();
						$bmarray = $bmlist->get_band_members();
						foreach ($bmarray as $bm) {
							$uo = $bm->getUserObject();
						?>
							<option value="<?=$uo->getID()?>"<? if ($user_id == $uo->getID()) { ?> SELECTED<? } ?>><?=$uo->getFirstName()?><? if (!$uo->isActive()) { ?> *<? } ?></option>
						<? } ?>
					</select>
		
			<? } else { 
				$uo = $sh->getUserObject();
				echo($uo->getFirstName());
			} ?>					
			</td>
			<td width="34%" valign="top">
			
			<strong>Date (<a style="vertical-align: middle" href="javascript:void(0)" onclick="popUpCalendar(this, document.getElementById('date'), '<?=DATE_JS_CALENDAR?>')">Calendar</a>)</strong><br/>
			<input name="date" id="date" class="text" type="text" value="<?=$date?>">
			
			</td>
			<td width="33%" valign="top">
						
			<strong>Time</strong><br/>
			<input name="time" id="time" class="text" type="text" value="<?=$time?>">
			</td>

		</tr>
		</table>
		<div class="edit-form">
		<strong>Description</strong><br/>
		<textarea name="description" id="description" class="mid"><?=$description?></textarea>
		</div>
		<div class="edit-form">
		<strong>Body</strong><br/><textarea name="body" id="body" class="full"><?=$body?></textarea>
		</div>
		
		<input type="submit" value="Update Entry" name="submit" class="button">
		<input type="submit" class="button" value="Exit Without Updating" name="preview" onclick="location.href='<?=$PHP_SELF?>?id=<?=$no->getID()?>'; return false" class="button">
		</form>
		</div>
				
		
	<? } else { ?>

		<h1>view entry:</h1>
		<div class="inset">
		
		<h2><?=$no->getTitle()?></h2>
		<span class="small">
			Posted By <strong><?
				$uo = $no->getUserObject();
				echo($uo->getFirstName());
			?></strong>
			on <strong><?=$no->getDateTime()?></strong>
			|
			Status: <? if ($no->isActive()) { ?><b>Active</b><? } else { ?><b>Inactive</b><? } ?>
		</span>
		<br><br>
		<? if ($no->getDescription()) { ?>
			<b>Description:</b><br>
			<?=$no->getDescription()?><br><br>
		<? } ?>
		<? if ($no->getBody()) { ?>
			<b>Body:</b><br>
			<?=$no->getBody()?><br><br>
		<? } ?>
		<form name="entry_status" method="get">
			<? if ($no->canEdit()) { ?>
				<input type="submit" name="" value="Edit Entry" onclick="location.href='<?=$PHP_SELF?>?task=edit&id=<?=$_GET['id']?>';return false" class="button">
				<? if ($no->isActive()) { ?><input type="submit" name="" value="Deactivate Entry" onclick="location.href='<?=$PHP_SELF?>?task=deactivate&id=<?=$_GET['id']?>';return false" class="button"><? } else { ?><input type="submit" name="" value="Activate Entry" onclick="location.href='<?=$PHP_SELF?>?task=activate&id=<?=$_GET['id']?>';return false" class="button"><? } ?>
				<input type="submit" value="Remove Entry" name="" onclick="if (confirm('Are you sure you wish to delete this entry?')) { location.href='<?=$PHP_SELF?>?task=delete&id=<?=$_GET['id']?>'};return false" class="button">
			<? } ?>
			<input type="submit" value="Return to News List" name="" onclick="location.href='band_news.php'; return false" class="button">
		</form>
		
		</div>
	<? } ?>

<? } else {
	$no->outputDialog('Return to Band List','band_news.php');
} ?>

<? include('layout/footer.php'); ?>
